#include "Program.h"

time_t duration;

Program::Program(std::string fileName)
{
	algorithm = NULL;
	std::ifstream file(fileName.c_str());
	if(file.is_open())
	{
		file>>size;
		size++;
		for(int i =1;i<size;i++)
		{
			State state;
			state.id = i;
			file>>state.r;
			file>>state.p;
			file>>state.q;
			states.push_back(state);
		}

		Run();
	}
	else
	{
		std::cout<<"Bad file name or file not exists."<<std::endl;
	}
}

void Program::Run()
{

	algorithm = new Algorithm(states);
	time_t start,stop;
	time(&start);
	algorithm->Schrage();
	//algorithm->SchragePmtn();
	time(&stop);
	std::cout<<"Size : "<<size-1;
	duration += (stop - start);
	std::cout<<" Duration : "<<duration<<" s cMax : "<<
		algorithm->GetCmax()<<std::endl;
	states = algorithm->GetStates();

	/*for(int x=1;x<states.size();x++)
		std::cout<<states[x].id<<" ";
	std::cout<<std::endl;*/
}

Program::~Program()
{	
	if(algorithm!=NULL)
	{
		algorithm->~Algorithm();
	}

}